

class FclShareItem {
  /// 用户id
  String userId;

  /// 会话id
  String slbsId;

  /// 纬度
  double latitude;

  /// 经度
  double longitude;
  /// 头像地址
  String? avatarUrl;

  FclShareItem({
    required this.userId,
    required this.slbsId,
    required this.latitude,
    required this.longitude,
    this.avatarUrl,
  });

  // 从 JSON 创建实例
  factory FclShareItem.fromJson(Map<String, dynamic> json) {
    return FclShareItem(
      userId: json['user_id'] as String,
      slbsId: json['slbs_id'] as String,
      latitude: json['point']['lat'] as double,
      longitude: json['point']['lng'] as double,
      avatarUrl: json['avatarUrl'] as String?,
    );
  }

  // 将实例转换为 JSON
  Map<String, dynamic> toJson() {
    return {
      'user_id': userId,
      'slbs_id': slbsId,
      'point': {
        'lat': latitude,
        'lng': longitude,
      },
      'avatarUrl': avatarUrl,
    };
  }

  bool isSelf() {
    return userId == '1';
  }

  double getLatitude() {
    if (latitude.toString().contains(RegExp(r'[eE+\-]')) ||
        latitude < -90 ||
        latitude > 90) {
      return 0;
    }
    return latitude;
  }

  double getLongitude() {
    if (longitude.toString().contains(RegExp(r'[eE+\-]')) ||
        longitude < -180 ||
        longitude > 180) {
      return 0;
    }
    return longitude;
  }
  
}
